//
//  DetailRealNameViewController.m
//  PigMarket
//
//  Created by mac on 2019/3/22.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "DetailRealNameViewController.h"
#import "SystemSetingCell.h"
#import "UploadIdCardViewController.h"

@interface DetailRealNameViewController ()<UITableViewDelegate,UITableViewDataSource>
/**
 myTableView
 */
@property (nonatomic , strong) UITableView *myTableView;

/**
 dataArr
 */
@property (nonatomic , strong) NSArray *dataArr;

/**
 tipsLab
 */
@property (nonatomic , strong) YYLabel *tipsLab;
@end

@implementation DetailRealNameViewController


#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.baseNavView.navTitleLabel.text = @"认证信息";
    [self setUpView];
}


#pragma mark - init method
- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}
- (void)initView {
    [self.view addSubview:self.myTableView];
}

- (void) initLayout {
    
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(TJ_NavBarHeight);
        make.left.right.bottom.mas_equalTo(self.view);
    }];
    
}

- (void) initAction {
    
}

- (void)initData {
    self.dataArr = @[@[@{@"title":@"姓名",@"detail":@"",@"rightArrow":@"1"},
                       @{@"title":@"性别",@"detail":@"",@"rightArrow":@"0"}],
                     @[@{@"title":@"证件号码",@"detail":@"",@"rightArrow":@"0"},
                       @{@"title":@"身份证有效期",@"detail":@"",@"rightArrow":@"1"}]];
}

#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.dataArr[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 1) {
        return 140;
    }
    return 0.001;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 140)];
    [footerView addSubview:self.tipsLab];
    [self.tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(10);
        make.right.mas_equalTo(-20);
    }];

    return footerView;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SystemSetingCell *cell = [SystemSetingCell cellWithTableView:tableView];

    cell.infoDic = self.dataArr[indexPath.section][indexPath.row];
    switch (indexPath.section) {
        case 0:
            if (indexPath.row == 0) {
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

            }else {
                cell.accessoryType = UITableViewCellAccessoryNone;
            }
            break;
        case 1:
            if (indexPath.row == 1) {
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                
            }else {
                cell.accessoryType = UITableViewCellAccessoryNone;
            }
            break;
        default:
            break;
    }

    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
            if (indexPath.row == 0) {
                UploadIdCardViewController *uploadVC = [[UploadIdCardViewController alloc] init];
                [self.navigationController pushViewController:uploadVC animated:YES];
            }
            break;
        case 1:
            if (indexPath.row == 1) {
                UploadIdCardViewController *uploadVC = [[UploadIdCardViewController alloc] init];
                [self.navigationController pushViewController:uploadVC animated:YES];
            }
            break;
        default:
            break;
    }
}
#pragma mark - target action
- (void)callUpService {
    [[AlertAction sharedInstance] showAlertWithTitle:@"提示" message:@"是否拨打400" confirmBtnTitle:@"确定" confirmBlock:^{
        
    } cancelBlock:nil];
}
#pragma mark - private method

#pragma mark - getter and setter
- (UITableView *)myTableView {
    if (!_myTableView) {
        _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableView.rowHeight = 54;
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
    }
    return _myTableView;
}
- (NSArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [[NSArray alloc] init];
    }
    return _dataArr;
}
- (YYLabel *)tipsLab {
    if (!_tipsLab) {
        _tipsLab = [[YYLabel alloc] init];
        _tipsLab.textColor = [UIColor tipsGrayColor];
        _tipsLab.font = [UIFont smallFont];
        NSString *tipsStr = @"如有任何问题，请及时与我们联系，电话:400-6666-8888";
        NSMutableAttributedString* text = [[NSMutableAttributedString alloc] initWithString:tipsStr];
        text.yy_font = [UIFont smallFont];
        text.yy_color = [UIColor tipsGrayColor];
        NSRange range = NSMakeRange(text.length - 13, 13);
        @weakify(self)
        [text yy_setTextHighlightRange:range color:[UIColor primaryColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            @strongify(self)
                [self callUpService];
        }];
        _tipsLab.attributedText = text;

    }
    return _tipsLab;
}


@end
